<?php
/*
 * (C) Copyright 2013 Torsten Gorath (http://www.blauesdach.de/).
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 * Contributors:
 *     Torsten Gorath
 */
require_once $basedir . "/inc/permissions.php";
class Menu {
    
    private $menu;
    private $current;
	private $level = 0;
    
    public function __construct($id) {
        $this->current = $id;
        $this->menu = array(
            'stammdaten' => array('Stammdaten',array(
                'stammdaten_adress' => 'Adressen',
                'stammdaten_bank' => 'Bankverbindungen',
                'stammdaten_mitglieder' => 'Mitglieder',
                'stammdaten_kinder' => 'Kinder',
                'stammdaten_mitarbeiter' => 'Mitarbeiter',
                'stammdaten_gruppen' => 'Gruppen',
                Permission::$STAMMDATEN_KONTEN => 'Eigene Konten'
            )),
            'kinder' => array('Kinder', array(
            	'kinder_vertraege' => 'Vertr&auml;ge',
            	'kinder_stadt' => 'Meldung Stadt'
			)),
			'gruppen' => array('Gruppen', array(
				'gruppen_einteilung' => 'Einteilung',
				'gruppenliste' => 'Gruppenlisten'
			)),
			Permission::$SETTING => array('Einstellungen', array(
			    Permission::$SETTING_ROLES => 'Rollenverwaltung',
                Permission::$SETTING_USER => 'Benutzerverwaltung'
            ))
        );
    }
    
    public function show($values=NULL) {
    	$this->level++;
        if($values==NULL) {
            $values = $this->menu;
	        echo "<ul id='menu' class='memu'>";
        } else {
            echo "<ul>";
        }
        foreach($values as $key => $value) {
            $activ = "";
            if($key == $this->current) {
                $activ = " memu-current";
            }
			$clazz = "";
			if($this->level==1) {
				$clazz = "memu-root";
			}
			$name = $value;
			if(is_array($value)) {
				$name = $value[0];
				if($this->level>1) {
					$clazz = "has-children";
				}
			}
            echo "<li class='".$clazz.$activ."'><a href='?page=".$key."'>".$name."</a>";
            if(is_array($value)) {
            	$this->show($value[1]);
            }
            echo "</li>";
        }
        echo "</ul>";
		$this->level--;
    }

}
?>